﻿@model Orchard.Markdown.ViewModels.EditMarkdownFieldViewModel
@using Orchard.ContentManagement.Metadata.Models
@using Orchard.Markdown.Settings;

@{
    var settings = Model.PartFieldDefinition.Settings.ToObject<MarkdownFieldSettings>();
}

<script name="simplemde" depends-on="admin" asp-src="/Orchard.Markdown/Scripts/simplemde.min.js" at="Foot"></script>
<style name="simplemde" asp-src="/Orchard.Markdown/Styles/simplemde.min.css"></style>


<fieldset class="form-group">
    <label asp-for="Markdown">@Model.PartFieldDefinition.DisplayName()</label>
    <textarea asp-for="Markdown" class="form-control content-preview-text"></textarea>
    @if (!String.IsNullOrEmpty(settings.Hint))
    {
        <span class="hint">@settings.Hint</span>
    }
</fieldset>

<script at="Foot">
    $(function () {
        var simplemde = new SimpleMDE({
            element: document.getElementById("@Html.IdFor(m => m.Markdown)"),
            forceSync: true
        });

        simplemde.codemirror.on('change', function () {
            $(document).trigger('contentpreview:render');
        });
    });
</script>